/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FrameWork.Objects.Chacracter.Enemy;

import FrameWork.GameScreen;
import FrameWork.Objects.Character.MyCharacter;
import FrameWork.Objects.MyObject;
import FrameWork.RSFont;
import FrameWork.RSMainGame;
import GamePlay.Global;
import java.io.IOException;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author DANTRUONG
 */
public class House extends Friend{
    public int m_Hp;
    public House(int _X,int _Y, int _SizeX, int _SizeY,
            float _TimeAni, float _Veloc,int _Direct,
            int _Map[][],int _Width, int _Height,
            int _ID) throws IOException{
        super(_X,_Y,_SizeX,_SizeY, _TimeAni, _Veloc,_Direct,_Map,_Width,_Height, _ID);
        m_STATUS = Global.STT_ACTIVE;
        m_Sprite = RSMainGame.getRS().getHouse();
        m_CurFrame  = 0;
        m_Hp = 5;
    }
    public void ActionCollision (MyObject _Object){
        
        if ( _Object.getSTATUS()==Global.STT_DEATH)return;
        
        switch (_Object.getID()){
            //<editor-fold defaultstate="collapsed" desc="Boom Explotion">
            case Global.ID_BOOM_EXPLOSION:
               if(m_STATUS==Global.STT_ACTIVE){
                        m_STATUS= Global.STT_INVI;
                        m_Hp --;
                        if(m_Hp <=0){
                            m_STATUS=Global.STT_DEATH;
                        }
                    }
                break;
            //</editor-fold> 
        }
    }
     public void Update (float _Time,int _Terrain[][]){
         m_SaveTimeFire+= _Time;
        if(m_SaveTimeFire>=0.2f){
            m_SaveTimeFire-=0.2f;
            m_FrameFire =(++ m_FrameFire)%7;
        }
        
        UpdateMove(_Time, _Terrain);
        UpdateAnimation(_Time);
//        Move(_Time, _Terrain);
        switch(m_STATUS){
            case Global.STT_INVI:
                m_TimeUpdate+=_Time;
                if(m_TimeUpdate>=2.0f){
                    m_TimeUpdate = 0;
                    m_STATUS= Global.STT_ACTIVE;                    
                }
                break;
        }
    }
     public void UpdateAI (float _Time,
              MyCharacter _Obj, Vector _Enemy,int _Terrain[][]){
         }
    public void UpdateAnimation(float _Time) {
    }
    public void DrawScreen (Graphics _Graphics,GameScreen _Screen){
        
        switch(m_STATUS){
        case Global.STT_INVI:
            if(m_Ran.nextInt(2)== 0){
                m_Sprite.setFrame(m_CurFrame);
                m_Sprite.setPosition((int)m_CurX - (_Screen.getXView() - _Screen.getWidth()/2), 
                    (int)m_CurY - (_Screen.getYView() - _Screen.getHeight()/2));
                m_Sprite.paint(_Graphics);
            }
            if(m_Ran.nextInt(2)== 0){
                DrawFire(_Graphics, _Screen);
            }
            
            break;
            
        case Global.STT_ACTIVE:
            
            m_Sprite.setFrame(m_CurFrame);
            m_Sprite.setPosition((int)m_CurX - (_Screen.getXView() - _Screen.getWidth()/2), 
                    (int)m_CurY - (_Screen.getYView() - _Screen.getHeight()/2));
            m_Sprite.paint(_Graphics);
            DrawFire(_Graphics, _Screen);
            break;
        case Global.STT_DEATH:
            m_Sprite.setFrame(m_CurFrame);
            m_Sprite.setPosition((int)m_CurX - (_Screen.getXView() - _Screen.getWidth()/2), 
                    (int)m_CurY - (_Screen.getYView() - _Screen.getHeight()/2));
            m_Sprite.paint(_Graphics);
        }
    }
    public void DrawFire (Graphics _Graphics,GameScreen _Screen){
        Sprite Fire= RSMainGame.getRS().getFire();
        //<editor-fold defaultstate="collapsed" desc="Fire in House">
            
            if(m_Hp>0){
                Fire.setFrame(m_FrameFire);
                Fire.setPosition((int)m_CurX +35 - (_Screen.getXView() - _Screen.getWidth()/2),
                        (int)m_CurY +30- 10 - (_Screen.getYView() - _Screen.getHeight()/2));
                Fire.paint(_Graphics);
            }
            if(m_Hp>1){
                Fire.setFrame(m_FrameFire);
                Fire.setPosition((int)m_CurX +60 - (_Screen.getXView() - _Screen.getWidth()/2),
                        (int)m_CurY - 10 - (_Screen.getYView() - _Screen.getHeight()/2));
                Fire.paint(_Graphics);
            }
            if(m_Hp>2){
                Fire.setFrame(m_FrameFire);
                Fire.setPosition((int)m_CurX +60 - (_Screen.getXView() - _Screen.getWidth()/2),
                        (int)m_CurY +60- 10 - (_Screen.getYView() - _Screen.getHeight()/2));
                Fire.paint(_Graphics);
            }
            if(m_Hp>3){
                Fire.setFrame(m_FrameFire);
                Fire.setPosition((int)m_CurX +5 - (_Screen.getXView() - _Screen.getWidth()/2),
                        (int)m_CurY +60- 10 - (_Screen.getYView() - _Screen.getHeight()/2));
                Fire.paint(_Graphics);
            }
            if(m_Hp>4){
                
                Fire.setFrame(m_FrameFire);
                Fire.setPosition((int)m_CurX +10  - (_Screen.getXView() - _Screen.getWidth()/2),
                        (int)m_CurY - 10 - (_Screen.getYView() - _Screen.getHeight()/2));
                Fire.paint(_Graphics);
            }
            //</editor-fold>
    }
}
